// index.ts
// 获取应用实例
const app = getApp<IAppOption>() as any
import { requestGET } from '../../utils/service'

Page({
  /**
   * 页面的初始数据
   */
  data: {
    packageList: [],
    imgUrl: app.globalData.commonUrl,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getPackageList()
  },

  // 获取体检包列表
  getPackageList() {
    requestGET("physicalexaminationpackage/getallphysicalexaminationpackages", {})
      .then((res: any) => {
        if (res.data.code == '200') {
          let list: any = res.data.data
          //if(list.length>=1) list = list.slice(0, 1)
          let array: any = [
            // { physicalExaminationPackageTitle: "颈椎、胸椎、腰椎36项细胞评估" },
            { physicalExaminationPackageTitle: "心脏5项细胞评估" },
            { physicalExaminationPackageTitle: "大脑7项细胞评估" },
            { physicalExaminationPackageTitle: "胃、十二指肠、胰腺8项细胞评估" },
            { physicalExaminationPackageTitle: "小肠、结肠、直肠3项细胞评估" },
            { physicalExaminationPackageTitle: "糖营养均衡细胞评估" },
            { physicalExaminationPackageTitle: "糖饮食结构细胞评估(胰岛素抵抗)" },
            { physicalExaminationPackageTitle: "糖损伤细胞评估" },
            { physicalExaminationPackageTitle: "雌激素紊乱性损伤细胞评估" },
            { physicalExaminationPackageTitle: "过敏原7项细胞评估" },
            { physicalExaminationPackageTitle: "子宫4项细胞评估" },
            { physicalExaminationPackageTitle: "卵巢5项细胞评估" },
            { physicalExaminationPackageTitle: "乳腺5项细胞评估" },
            { physicalExaminationPackageTitle: "肺、气管、喉7项细胞评估" },
            // { physicalExaminationPackageTitle: "四肢关节16项细胞评估" },
            { physicalExaminationPackageTitle: "甲状腺3项细胞评估" },
            { physicalExaminationPackageTitle: "前列腺2项细胞评估" }
          ];
          list = list.concat(array)
          this.setData({
            packageList: list
          })          
        } else {
          wx.showToast({
            title: '服务异常',
            icon: 'error',
            duration: 2000
          })
        }
      })
  },

  // 跳转到体检包详情
  jumpToDetail(e: any) {
    // 未注册
    if (wx.getStorageSync('logInStatus') == 'notRegister') {
      wx.showModal({
        title: '提示',
        content: '预约需要您先进行注册，是否去注册?',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
            wx.navigateTo({
              url: '/pages/register/index',
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
      return
    }
    const pageData = e.currentTarget.dataset.id
    const url = "/pages/payPage/index?physicalExaminationPackageId=" + pageData.physicalExaminationPackageId + '&physicalExaminationPackagePrice=' + pageData.physicalExaminationPackagePrice + '&physicalExaminationLocation=' + pageData.physicalExaminationLocation + '&physicalExaminationPackageTitle=' + pageData.physicalExaminationPackageTitle
    // const url = '/pages/packageDetail/index?id=' + e.currentTarget.dataset.id
    wx.navigateTo({
      url: url,
    })
  },
})

